<template>
    <div class="shop_info">
        <!-- 企业信息-->
        <div class="enterise_info_title" style="font-size: 0.32rem;">请选择企业类型</div>
        <div class="enterise_info_tab">
            <van-button class="enterise_info_tab_btn" v-for="item, index in tabList" plain type="danger"
                @click="tabClick(item.id)" :key="index"
                :style="{ background: current == item.id ? '#FDE9E9' : '#FFF' }">{{
                item.name
            }}</van-button>
        </div>
        <van-form  error-message-align="right" input-align="right" @submit="onSubmit">
            <div class="enterise_info_title"><span>*</span>店铺信息</div>
            <div class="enterise_info_current" v-if="current != 3">营业执照 <span>(请上传营业执照相关图片)</span></div>
            <van-field name="license_url" v-if="current != 3" label="" label-width="0.01rem">
                <template #input>
                    <van-uploader  v-model="license_url" :max-count="1" preview-size="100%" :after-read="afterReadLicense"
                    :before-delete="uploadDleteLicense"  :rules="[{ required: true, message: '请上传营业执照' }]">
                        <img src="../../../../images/mine/tianjia.png" alt="" class="tianjia_pic">
                    </van-uploader>
                    <!-- <div class="tianjia_text">请上传清晰的包含人脸的身份证照片</div> -->
                </template>
            </van-field>
            <!-- <div class="enterise_info_title">营业执照</div> -->
            <van-field v-if="current != 3" v-model="business_license.company_name" name="company_name" label="营业执照名称" placeholder="营业执照名称"
            readonly   :rules="[{ required: true, message: '营业执照名称' }]" />
            <van-field v-if="current != 3" v-model="business_license.credit_code" name="credit_code" label="营业执照号码" placeholder="营业执照号码"
            readonly  :rules="[{ required: true, message: '营业执照号码' }]" />
            <van-field label-width="3.2rem" v-if="current != 3" readonly clickable is-link name="type" :value="business_license.duration_type" label="营业执照有效期"
               placeholder="营业执照有效期" />
            <van-field v-if="current != 3" readonly clickable is-link v-model="business_license.establish_date" name="establish" label="营业注册时间"
              placeholder="营业注册时间" :rules="[{ required: true, message: '营业注册时间' }]"
                />
                <!-- @click="showPicker = true" @click="showPickerTime = true"   @click="showPickerEndTime = true" -->
            <van-field v-if="current != 3" readonly clickable is-link v-model="business_license.expiry_date" name="expiry" label="有效截止时间"
              placeholder="有效截止时间" :rules="[{ required: true, message: '有效截止时间' }]"
               />

      <van-field
        readonly
        clickable
        name="cate_name"
        :value="cate_name"
        label="店铺类型"
        placeholder="请选择店铺类型"
        @click="showMcc = true"
        is-link
        :rules="[{ required: true, message: '选择店铺类型' }]"
      />

      <!-- 666 -->
       <!-- <AMap></AMap> -->
       <van-field
        v-model="region_name"
        name="region_name"
        readonly
        autosize
        rows="1"
        type="textarea"
        label="商家地址"
        placeholder="请选择商家地址"
        @click="showMap= true"
        is-link
        :rules="[{ required: true, message: '选择商家地址' }]"
      />
      <!-- <van-field
        v-model="region_name"
        name="region_name"
        readonly
        label="商家地址"
        is-link
        placeholder="请选择商家地址"
        @click="showPopup = true"
      /> -->
            <van-field v-model="address" name="address" label="详细地址" placeholder="请输入详细地址"
                :rules="[{ required: true, message: '请输入详细地址' }]" />
                <van-field name="cover_url" label="" label-width="4rem"  :rules="[{ required: true, message: '不能为空' }]">
                <template #label>
                    <div class="shop_upload_text">
                        <div>上传店铺图片</div>
                        <div>保证照片清晰可见</div>
                        <div  @click="getExample('merchant_store_head')">查看示例</div>
                    </div>
                </template>
                <template #input>
                    <van-uploader v-model="image_data.cover_url" :max-count="1" :after-read="afterReadCover"
                    :before-delete="uploadDleteCover">
                        <img src="../../../../images/mine/icon_tup.png" alt="" class="shop_upload_img">
                    </van-uploader>
                </template>
            </van-field>
            <!-- :rules="[{ required: true, message: '请输入社会信用代码' }]" -->
            <van-field name="head_image_url" label="" label-width="4rem" :rules="[{ required: true, message: '不能为空' }]">
                <template #label>
                    <div class="shop_upload_text">
                        <div>{{ current==1?'上传公司大楼照':'上传门头照' }}</div>
                        <div>保证照片清晰可见</div>
                        <div  @click="getExample('merchant_store_head')">查看示例</div>
                    </div>
                </template>
                <template #input>
                    <van-uploader v-model="image_data.head_image_url" :max-count="1" :after-read="afterReadHead"
                    :before-delete="uploadDleteHead">
                        <img src="../../../../images/mine/icon_tup.png" alt="" class="shop_upload_img">
                    </van-uploader>
                </template>
            </van-field>

            <!-- :rules="[{ required: true, message: '请输入社会信用代码' }]" -->
            <van-field v-if="current==1" name="company_front_image_url" label="" label-width="4rem"  :rules="[{ required: true, message: '不能为空' }]">
                <template #label>
                    <div class="shop_upload_text">
                        <div>上传前台照</div>
                        <div>保证照片清晰可见</div>
                        <div  @click="getExample('merchant_check_out')">查看示例</div>
                    </div>
                </template>
                <template #input>
                    <van-uploader  v-model="image_data.company_front_image_url" :max-count="1" :after-read="afterReadCheckouts"
                    :before-delete="uploadDleteCheckouts">
                        <img src="../../../../images/mine/icon_tup.png" alt="" class="shop_upload_img">
                    </van-uploader>
                </template>
            </van-field>
            <!--  v-if="current==2" -->
            <van-field v-else  name="check_out_image_url" label="" label-width="4rem"  :rules="[{ required: true, message: '不能为空' }]">
                <template #label>
                    <div class="shop_upload_text">
                        <div>上传收银台照</div>
                        <div>保证照片清晰可见</div>
                        <div  @click="getExample('merchant_check_out')">查看示例</div>
                    </div>
                </template>
                <template #input>
                    <van-uploader  v-model="image_data.check_out_image_url" :max-count="1" :after-read="afterReadCheckout"
                    :before-delete="uploadDleteCheckout">
                        <img src="../../../../images/mine/icon_tup.png" alt="" class="shop_upload_img">
                    </van-uploader>
                </template>
            </van-field>
            <!-- :rules="[{ required: true, message: '请输入社会信用代码' }]" -->
            <van-field name="inside_image_url" label="" label-width="4rem"  :rules="[{ required: true, message: '不能为空' }]">
                <template #label>
                    <div class="shop_upload_text">
                        <div>上传商户内景照</div>
                        <div>保证照片清晰可见</div>
                        <div  @click="getExample('merchant_inside')">查看示例</div>
                    </div>
                </template>
                <template #input>
                    <van-uploader v-model="image_data.inside_image_url" :max-count="1" :after-read="afterReadInside"
                    :before-delete="uploadDleteInside">
                        <img src="../../../../images/mine/icon_tup.png" alt="" class="shop_upload_img">
                    </van-uploader>
                </template>
            </van-field>
            <div class="enterise_info_title"><span>*</span>法人信息</div>
            <div class="enterise_info_upload_title">请绑定您的身份证</div>
            <van-field name="front_url" label="" label-width="0.01rem" style="padding-bottom: 0.6rem;"  :rules="[{ required: true, message: '不能为空' }]">
                <template #input>
                    <van-uploader v-model="front_url" :max-count="1" preview-size="100%" :after-read="afterReadFront"
                    :before-delete="uploadDleteFront">
                        <img src="../../../../images/mine/tianjia.png" alt="" class="tianjia_pic">
                    </van-uploader>
                    <div class="tianjia_text">请上传清晰的包含人脸的身份证照片</div>
                </template>
            </van-field>
            <van-field name="back_url" label="" label-width="0.01rem" style="padding-bottom: 0.6rem;"  :rules="[{ required: true, message: '不能为空' }]">
                <template #input>
                    <van-uploader v-model="back_url" :max-count="1" preview-size="100%" :after-read="afterReadBack"
                    :before-delete="uploadDleteBack">
                        <img src="../../../../images/mine/tianjia.png" alt="" class="tianjia_pic">
                    </van-uploader>
                    <div class="tianjia_text">请上传清晰的包含国徽的身份证照片</div>
                </template>
            </van-field>
            <van-field v-model="legal_person.name" name="name" label="法人姓名" placeholder="法人姓名"
                :rules="[{ required: true, message: '法人姓名' }]" />
            <van-field v-model="legal_person.identity_card_no" name="identity_card_no" label="身份证号" placeholder="后6位作为APP初始登录密码"
            readonly :rules="[{ required: true, message: '身份证号' }]" />
                <!-- @click="showPickerCard = true"   @click="showPickerCardTime = true"  @click="showPickerCardEndTime = true" -->
            <van-field readonly clickable is-link name="duration_type" :value="legal_person.duration_type" label="期限类型" placeholder="请选择"
               />
            <van-field label-width="3.2rem" readonly clickable is-link v-model="legal_person.issue_date" name="issue_date" label="身份证发放日期"
                placeholder="身份证发放日期" :rules="[{ required: true, message: '身份证发放日期' }]"
               />
            <van-field label-width="3.2rem" readonly clickable is-link v-model="legal_person.expiry_date" name="expiry_date" label="身份证有效日期"
                placeholder="身份证有效日期" :rules="[{ required: true, message: '身份证有效日期' }]"
                />
            <div class="enterise_info_text">注：如身份证有误，请联系客服修改</div>
            <div style="margin: 16px;">
                <!-- <van-button round block type="default" @click="backBtn"style="width: 95%;margin: 0.32rem auto;"
                >上一步</van-button> -->
                <van-button round block type="info" native-type="submit"
                    color="linear-gradient(to right, #FF5851, #E9011B)">下一步</van-button>
            </div>
        </van-form>
        <!-- 地图  @onCancel="showMap==false"-->
         <AMap v-if="showMap" @marker="mapClick"
          :lons="longitude" :lats="latitude" :region="region_name" :code="region_code"></AMap>
        <!-- 营业执照有效期 -->
        <van-popup v-model="showPicker" position="bottom">
            <van-picker show-toolbar :columns="columns" @confirm="onConfirm" @cancel="showPicker = false"
            :value="business_license.duration_type">
            </van-picker>
        </van-popup>
        <!-- 营业执照注册时间 -->
        <van-popup v-model="showPickerTime" position="bottom">
            <van-datetime-picker type="date" @confirm="onConfirmTime" @cancel="showPickerTime = false"
                :min-date="minDate" :max-date="maxDate" :value="new Date(business_license.establish_date)"/>
        </van-popup>
        <!-- 营业执照截止时间 showPickerEndTime-->
        <van-popup v-model="showPickerEndTime" position="bottom">
        </van-popup>
        <!-- 营业执照注册时间 -->
        <van-popup v-model="showPickerTime" position="bottom">
            <van-datetime-picker type="date" @confirm="onConfirmTime" @cancel="showPickerTime = false"
                :min-date="minDate" :max-date="maxDate" :value="new Date(business_license.establish_date)"/>
        </van-popup>
        <!-- 营业执照截止时间 showPickerEndTime-->
        <van-popup v-model="showPickerEndTime" position="bottom">
            <van-datetime-picker type="date" @confirm="onConfirmEndTime" @cancel="showPickerEndTime = false"
                :min-date="minDate" :max-date="maxDate" :value="new Date(business_license.expiry_date)"/>
        </van-popup>
    <!-- 省市区 -->
    <van-popup v-model="showPopup" position="bottom">
      <van-cascader
        v-model="cascaderValue"
        title="请选择地址"
        :options="options"
        @close="showPopup = false"
        @change="onChange"
        @finish="onFinish"
      />
    </van-popup>
    <!-- 经营类目 -->
    <van-popup v-model="showMcc" position="bottom">
      <!-- <van-area :area-list="mccList" @confirm="onConfirmMcc" @cancel="showMcc = false" /> -->
      <van-cascader
        :field-names="fieldNames"
        v-model="cascaderValueMcc"
        title="请选择店铺类型"
        :options="optionsMcc"
        @close="showMcc = false"
        @finish="onFinishMcc"
      />
    </van-popup>
        <!-- 身份证期限 -->
        <van-popup v-model="showPickerCard" position="bottom">
            <van-picker show-toolbar :columns="columnsCard"
             @confirm="onConfirmCard" @cancel="showPickerCard = false" :value="legal_person.duration_type"/>
        </van-popup>
        <!-- 身份证发放 -->
        <van-popup v-model="showPickerCardTime" position="bottom">
            <van-datetime-picker type="date" @confirm="onConfirmCardTime" @cancel="showPickerCardTime = false"
                :min-date="minDate" :max-date="maxDate" :value="new Date(legal_person.issue_date)" swipe-duration="500">
            </van-datetime-picker>
        </van-popup>
        <!-- 身份证截止 showPickerEndTime-->
        <van-popup v-model="showPickerCardEndTime" position="bottom">
            <van-datetime-picker type="date" @confirm="onConfirmCardEndTime" @cancel="showPickerCardEndTime = false"
                :min-date="minDate" :max-date="maxDate" :value="new Date(legal_person.expiry_date)"/>
        </van-popup>
        <van-popup v-model="showExaplePopup" :style="{ width: '80%' }" >
          <div class="popup_example">
            <img :src="example.content" alt="">
            <div>{{ example.tip_msg }}</div>
          </div>
        </van-popup>
        <!-- <div style="position: fixed;bottom: 50px;width: 100%"> -->
                <van-button round block type="info" @click="onDraft" style="width: 90%;margin: 0.32rem auto;"  v-if="info.id<=0"
                    color="linear-gradient(to right, #FF5851, #E9011B)">暂存草稿</van-button>
            <!-- </div> -->
    </div>
</template>
<script>
import {parseTime} from '@/tool/methods'
import {CATE_LIST,OCR_RECOGNIZE,CACHE_INFO,CACHE_COMMIT } from '@/api/mine'
import { REGION_LIST} from '@/api/home';
import { getOssParams, uploadImage, uploadDelete ,getExampleList} from "@/api/upload";
import AMap from '@/components/map.vue';
import { setImageUrl ,getImageUrl} from '@/api/upload'; // Adjust the path accordingly
export default({
    props:["info"],
    components:{AMap}, 
    data() {
        return {
            example:{},
            showExaplePopup:false,
                  // 省市区
      selectAreaList: [], // 已选中地区
      showPopup: false,
      cascaderValue: "",
      options: [],
      tabIndex: 0,
      // 经营类目
      showMcc:false,
      optionsMcc: [],
      selectMccList: [],
      cascaderValueMcc: "",
      fieldNames: {
        text: "name",
        value: "id",
        children: "children",
      },
            // 营业执照有效期
            showPicker:false,
            columns:['长期','短期'],
            columnsCard:['长期','短期'],
            // 营业执照注册时间
            showPickerTime:false,
            minDate: new Date(1937, 0, 1),
            maxDate: new Date(2099, 10, 1),
            // 营业执照截止时间
            showPickerEndTime:false,
            // 商家地址
            showArea:false,
            areaList:{},
            // 身份证日期
            showPickerCard:false,
            showPickerCardTime:false,
            showPickerCardEndTime:false,

            username: '',
            uploader:[],
            current:3,
            tabList:[
                {
                    id:3,
                    name:'小微商户'
                },
                {
                    id:2,
                    name:'个体工商户'
                },
                {
                    id:1,
                    name:'企业'
                }
            ],
            business_info:{},
            business_license:{
                duration_type:''
            },
            license_url:[],
            cate_name:"",
            cate_id:"",
            region_name:"",
            region_code:"",
            address:"",
            latitude:"",
            longitude:"",
            image_data:{
                head_image_url:[],
                inside_image_url:[],
                check_out_image_url:[],
                cover_url:[],
                company_front_image_url:[]
            },
            front_url:[],
            back_url:[],
            legal_person:{
            },
            legal_info:{},
            showMap:false,
            business_scope:'',
            settleInfo:{}
        }
    },
    mounted() {
    window.scrollTo(0, 0)

        this.fetchRegions(1, 0);
        this.fetchRegionsMcc(1, 0);
        let params={
            type:'store',
            key:'enterpriseInfo',

        }
        if(this.info.id<=0){
        this.$http.get(CACHE_INFO,{params:params}).then(res=>{            
                if(res.data.content!=''){
                    const data = JSON.parse(res.data.content);
                    console.log(data);
                    
                    this.cate_name = data.cate_name;
            this.cate_id = data.cate_id;
            this.region_name = data.region_name;
            this.latitude = data.latitude;
            this.longitude = data.longitude;
            this.region_code = data.region_code;
            this.address = data.address ;
            // 处理图片数据
            this.business_license = data.business_license || {};
            this.legal_person = data.legal_person || {};
            this.legal_info=data.legal_person || {};
            this.image_data.head_image_url = setImageUrl(data.image_data.head_image_url)
            this.image_data.inside_image_url = setImageUrl(data.image_data.inside_image_url);
            this.image_data.check_out_image_url = setImageUrl(data.image_data.check_out_image_url);
            this.image_data.company_front_image_url = setImageUrl(data.image_data.company_front_image_url);
            this.image_data.cover_url = setImageUrl(data.cover_url);  
            this.business_info=data.business_license || {};
            this.business_license.license_url=data.business_license.license_url
            this.business_info.license_url=data.business_license.license_url
            this.front_url = setImageUrl(data.legal_person.front_url);
            this.back_url = setImageUrl(data.legal_person.back_url);
            this.license_url=setImageUrl(data.business_license.license_url )
            this.current=data.company_type
                }

        })
        } else{
                setTimeout(()=>{
            this.cate_name=this.info.cate_name
            this.cate_id=this.info.cate_id
            this.cascaderValueMcc=this.info.cate_id;
            this.region_name=this.info.region_name;
            this.latitude=String(this.info.latitude),
            this.longitude=String(this.info.longitude),
            this.region_code=this.info.region_code
            this.cascaderValue=this.info.region_code;
            this.address=this.info.address
            this.current=this.info.company_type
            this.license_url=this.info.business_license.license_url==''?[]:[{url:this.info.business_license.license_url}]

            this.image_data.head_image_url=this.info.image_data.head_image_url==''?[]:[{url:this.info.image_data.head_image_url}]
            this.image_data.inside_image_url=this.info.image_data.inside_image_url==''?[]:[{url:this.info.image_data.inside_image_url}]
            this.image_data.check_out_image_url=this.info.image_data.check_out_image_url==''?[]:[{url:this.info.image_data.check_out_image_url}]
            this.image_data.company_front_image_url=this.info.image_data.company_front_image_url==''?[]:[{url:this.info.image_data.company_front_image_url}]
            this.image_data.cover_url=this.info.cover_url==''?[]:[{url:this.info.cover_url}]
            
            this.business_license=this.info.business_license
            this.business_info=this.info.business_license
            this.business_scope=this.info.business_license.business_scope
            this.legal_person=this.info.legal_person
            this.legal_info=this.info.legal_person;
            this.front_url=this.info.legal_person.front_url==''?[] : [{url:this.info.legal_person.front_url}]
            this.back_url=this.info.legal_person.back_url==''?[] : [{url:this.info.legal_person.back_url}]
        },100)
            }

    },
    methods: {
        async  getExample(key){
            this.example=await getExampleList(this.$http,key)
            this.showExaplePopup=true
        },
    // 选择器变化时的回调
    onChange(res) {
      this.tabIndex = res.tabIndex;
      if (this.tabIndex === 3) {
        return;
      }

      //点击加载下一级回调
      this.getSpaceListAgain(res.selectedOptions, res.value);
    },
    getSpaceListAgain(selectedOptions, value) {
      this.$http
        .get(REGION_LIST, {
          params: {
            code: value,
          },
        })
        .then((res) => {
          let { data } = res;

		  if(this.tabIndex == 2 && !data.length) {
		  	data = [{
		  		code: 0,
		  		name: '暂不选择',
		  		parent_code: value
		  	}]
		  }

          if (data && data.length) {
            this.setOptions(selectedOptions, data);
          }
        });
    },
    setOptions(selectedOptions, data) {
      let _options = this.options;
      selectedOptions.forEach((item, index) => {
        if (index) {
          //不是第一个则取下一级children
          _options = _options.children;
        }
        _options =
          _options[_options.findIndex((_item) => _item.value === item.value)];
      });
      //找到最后一级
      _options.children = data.map((item) => {
        return {
          text: item.name,
          value: item.code,
          children: this.tabIndex == 2 ? null : [],
        };
      });
    },
    // 确定省市区
    onFinish({ selectedOptions }) {
      this.showPopup = false;

      this.selectAreaList = selectedOptions;

      selectedOptions = selectedOptions.filter((item) => {
        return item.value !== 0;
      });

      this.region_name = selectedOptions.map((option) => option.text).join("/");
    },
    async fetchRegions(parentCode, level) {
      const res = await this.$http.get(REGION_LIST, {
        params: {
          code: parentCode,
        },
      });
      let { data } = res;

	  if(level == 3 && !data.length) {
	  	data = [{
	  		name: '暂无选择',
	  		code: 0,
	  		parent_code: parentCode
	  	}]
	  }

      // 省级
      if (level === 0) {
        data.forEach((item) => {
          this.options.push({
            text: item.name,
            value: item.code,
            children: [],
          });
        });
      } else if (level === 1) {
        // 市级数据
        const province = this.options.find((item) => item.value === parentCode);
        if (province) {
          province.children = data.map((item) => ({
            text: item.name,
            value: item.code,
            children: [],
          }));
        }
      } else if (level === 2) {
        // 区/县级数据
        this.options.forEach((province) => {
          const city = province.children.find(
            (item) => item.value === parentCode
          );
          if (city) {
            city.children = data.map((item) => ({
              text: item.name,
              value: item.code,
              children: [],
            }));
          }
        });
      } else if (level === 3) {
        // 街道数据
        this.options.forEach((province) => {
          province.children.forEach((city) => {
            const county = city.children.find(
              (item) => item.value === parentCode
            );
            if (county) {
              county.children = data.map((item) => ({
                text: item.name,
                value: item.code,
              }));
            }
          });
        });
      }
    },
    // 经营类目
    async fetchRegionsMcc(parentCode, level) {
        //
      const res = await this.$http.get(CATE_LIST);
      this.optionsMcc = res.data;
    },
    // 确定类目
    onFinishMcc({ selectedOptions }) {
      this.showMcc = false;

      this.selectMccList = selectedOptions;
      this.cate_id = selectedOptions[selectedOptions.length - 1].id;


      selectedOptions = selectedOptions.filter((item) => {
        return item.value !== 0;
      });

      this.cate_name = selectedOptions.map((option) => option.name).join("/");
    },




        // 切换企业类型
        tabClick(id){
            this.current = id
            // if(this.current==2){
            //     this.image_data.check_out_image_url= this.image_data.company_front_image_url
            //     this.image_data.company_front_image_url=[]

            // }else if(this.current==1){
            //     this.image_data.company_front_image_url=this.image_data.check_out_image_url
            //     this.image_data.check_out_image_url=[]
            // }
        },
        // 营业执照有效期 长期短期
        onConfirm(value) {

            this.business_license.duration_type = value;
            this.showPicker = false;
        },
        // 营业执照注册时间
        onConfirmTime(time) {
            this.business_license.establish_date = parseTime(time, '{y}-{m}-{d}');
            this.showPickerTime = false;
        },
        // 营业执照截止时间
        onConfirmEndTime(time){
            this.business_license.expiry_date = parseTime(time, '{y}-{m}-{d}');
            this.showPickerEndTime = false;
        },
        // 上传营业执照
        async afterReadLicense(file) {
            try {

             // 获取OSS上传参数
            if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                this.ossParams = await getOssParams(this.$http);
            }
            if (!this.ossParams) {
                throw new Error('OSS参数未正确设置');
            }
            // 调用封装的上传函数
            await uploadImage(file, this.ossParams, this.license_url);
            let params={
                type:'business_license',
                image_url:this.license_url.map(item=>item.url)[0]
            }
            this.$http.post(OCR_RECOGNIZE,params).then(res=>{

                this.business_license=res.data.business_license
                this.business_info=res.data.business_license
                this.credit_code=res.data.business_license.credit_code
                this.company_name=res.data.business_license.company_name
                this.expiry=res.data.business_license.expiry_date
                this.establish=res.data.business_license.establish_date
                this.type=res.data.business_license.duration_type
                this.business_scope=res.data.business_license.business_scope;

            })
            } catch (error) {
                console.error('处理上传错误:', error);
            }
        },
        // 删除营业执照
        uploadDleteLicense(file) {
            this.license_url = uploadDelete(file, this.license_url);
            this.business_license={}
        },
        // 上传店铺图片
        async afterReadCover(file){
            try {
             // 获取OSS上传参数
            if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                this.ossParams = await getOssParams(this.$http);
            }
            if (!this.ossParams) {
                throw new Error('OSS参数未正确设置');
            }
            // 调用封装的上传函数
            await uploadImage(file, this.ossParams, this.image_data.cover_url);
            } catch (error) {
                console.error('处理上传错误:', error);
            }
        },
        // 删除店铺图片
        uploadDleteCover(file) {
            this.image_data.cover_url = uploadDelete(file, this.image_data.cover_url);
        },
        // 上传门头照
        async afterReadHead(file){
            try {
             // 获取OSS上传参数
            if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                this.ossParams = await getOssParams(this.$http);
            }
            if (!this.ossParams) {
                throw new Error('OSS参数未正确设置');
            }
            // 调用封装的上传函数
            await uploadImage(file, this.ossParams, this.image_data.head_image_url);
            } catch (error) {
                console.error('处理上传错误:', error);
            }
        },
        // 删除门头照
        uploadDleteHead(file) {
                this.image_data.head_image_url = uploadDelete(file, this.image_data.head_image_url);

        },
                // 上传收银台
                async afterReadCheckouts(file){
            try {
             // 获取OSS上传参数
            if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                this.ossParams = await getOssParams(this.$http);
            }
            if (!this.ossParams) {
                throw new Error('OSS参数未正确设置');
            }
            // 调用封装的上传函数
                await uploadImage(file, this.ossParams, this.image_data.company_front_image_url);
                console.log(this.image_data.company_front_image_url);
                
        } catch (error) {
                console.error('处理上传错误:', error);
            }
        },
        // 删除收银台
        uploadDleteCheckouts(file) {
                this.image_data.company_front_image_url = uploadDelete(file, this.image_data.company_front_image_url);
        },
        // 上传收银台
        async afterReadCheckout(file){
            try {
             // 获取OSS上传参数
            if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                this.ossParams = await getOssParams(this.$http);
            }
            if (!this.ossParams) {
                throw new Error('OSS参数未正确设置');
            }
            // 调用封装的上传函数
                await uploadImage(file, this.ossParams, this.image_data.check_out_image_url);
                console.log(this.image_data.check_out_image_url);
        } catch (error) {
                console.error('处理上传错误:', error);
            }
        },
        // 删除收银台
        uploadDleteCheckout(file) {
                this.image_data.check_out_image_url = uploadDelete(file, this.image_data.check_out_image_url);
        },
        // 上传内景
        async afterReadInside(file){
            try {
             // 获取OSS上传参数
            if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                this.ossParams = await getOssParams(this.$http);
            }
            if (!this.ossParams) {
                throw new Error('OSS参数未正确设置');
            }
            // 调用封装的上传函数
            await uploadImage(file, this.ossParams, this.image_data.inside_image_url);
            } catch (error) {
                console.error('处理上传错误:', error);
            }
        },
        // 删除内景
        uploadDleteInside(file) {
            this.image_data.inside_image_url = uploadDelete(file, this.image_data.inside_image_url);
        },
    // 上传身份证正面
    async afterReadFront(file) {
      try {
        // 获取OSS上传参数
        if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
          this.ossParams = await getOssParams(this.$http);
        }
        if (!this.ossParams) {
          throw new Error("OSS参数未正确设置");
        }
        // 调用封装的上传函数
        await uploadImage(file, this.ossParams, this.front_url);
        let params = {
          type: "identity_card",
          image_url: this.front_url.map((item) => item.url)[0],
          face: true,
        };
        this.$http.post(OCR_RECOGNIZE, params).then((res) => {
          console.log(res);
          this.legal_person = res.data.identity_card;
          this.legal_info=res.data.identity_card
          this.legal_person.name = res.data.identity_card.name;
          this.legal_person.identity_card_no = res.data.identity_card.identity_card_no;
        });
      } catch (error) {
        console.error("处理上传错误:", error);
      }
    },
    // 删除身份证正面
    uploadDleteFront(file) {
      this.front_url = uploadDelete(file, this.front_url);
    //   this.identity_card = {};
    },
    // 上传身份证反面
    async afterReadBack(file) {
      try {
        // 获取OSS上传参数
        if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
          this.ossParams = await getOssParams(this.$http);
        }
        if (!this.ossParams) {
          throw new Error("OSS参数未正确设置");
        }
        // 调用封装的上传函数
        await uploadImage(file, this.ossParams, this.back_url);
        let params = {
          type: "identity_card",
          image_url: this.back_url.map((item) => item.url)[0],
          face: false,
        };
        this.$http.post(OCR_RECOGNIZE, params).then((res) => {
          // console.log(res);
        //   this.legal_person = res.data.identity_card;
        //   this.legal_info=res.data.identity_card

          this.legal_person.duration_type =res.data.identity_card.duration_type;
          this.legal_person.expiry_date = res.data.identity_card.expiry_date;
          this.legal_person.issue_authority =res.data.identity_card.issue_authority;
          this.legal_person.issue_date = res.data.identity_card.issue_date;
          this.legal_info.duration_type =res.data.identity_card.duration_type;
          this.legal_info.expiry_date = res.data.identity_card.expiry_date;
          this.legal_info.issue_authority =res.data.identity_card.issue_authority;
          this.legal_info.issue_date = res.data.identity_card.issue_date;
        });
      } catch (error) {
        console.error("处理上传错误:", error);
      }
    },
    // 删除身份证反面
    uploadDleteBack(file) {
      this.back_url = uploadDelete(file, this.back_url);
      // this.identity_card={}
    },
        // s身份证有效期 长期短期
        onConfirmCard(value) {
            this.legal_person.duration_type = value;
            this.showPickerCard = false;
        },
        // 身份证发放日期
        onConfirmCardTime(time){
            this.legal_person.issue_date = parseTime(time, '{y}-{m}-{d}');
            this.showPickerCardTime = false;
        },
        // 身份证截止日期
        onConfirmCardEndTime(time){
            this.legal_person.expiry_date = parseTime(time, '{y}-{m}-{d}');
            this.showPickerCardEndTime = false;
        },
        // 地图经纬度
        mapClick(value,msg){
            if(msg==0){
                this.region_code=value.region_code
                this.region_name=value.region_name
                this.longitude=value.longitude
                this.latitude=value.latitude
            }
            this.showMap=false
        },
        onSubmit(values) {
            let business_license={
                license_url: values.license_url==undefined?'':values.license_url[0]?.url || '',
                ...this.business_info,
                // credit_code:this.credit_code,
                // company_name:this.company_name
                // expiry_date:this.expiry
                // establish_date:this.establish
                // duration_type:this.type
                business_scope:this.business_scope
            }

            let params={
                longitude:this.longitude,
                latitude:this.latitude,
                address:this.address,
                region_name:this.region_name,
                region_code:this.region_code,
                cate_name:this.cate_name,
                cate_id:this.cate_id,
                company_type:this.current,
                cover_url:this.image_data.cover_url==undefined?'':this.image_data.cover_url[0]?.url || '',
            }
            let image={
                head_image_url: this.image_data.head_image_url==undefined?'':this.image_data.head_image_url[0]?.url || '',
                inside_image_url: this.image_data.inside_image_url==undefined?'':this.image_data.inside_image_url[0]?.url || '',
                check_out_image_url: this.image_data.check_out_image_url==undefined?'':this.image_data.check_out_image_url[0]?.url || '',
                company_front_image_url: this.image_data.company_front_image_url==undefined?'':this.image_data.company_front_image_url[0]?.url || '',
            }
            let legal={
                ...this.legal_info,
                name:this.legal_person.name,

                front_url: this.front_url==undefined?'':this.front_url[0]?.url || '',
                back_url: this.back_url==undefined?'':this.back_url[0]?.url || '',
            }
            this.settleInfo={
                cate_name: this.cate_name,
                cate_id: this.cate_id,
                region_name: this.region_name,
                latitude: this.latitude,
                longitude: this.longitude,
                region_code: this.region_code,
                address: this.address,
                image_data: this.image_data,
                business_license: {
                    ...this.business_license,
                    license_url:getImageUrl(this.license_url),
                },
                legal_person:{
                    ...this.legal_person,
                    front_url: getImageUrl(this.front_url),
                    back_url: getImageUrl(this.back_url),
                    
                },
                image_data:{
                    head_image_url :getImageUrl(this.image_data.head_image_url),
                    inside_image_url : getImageUrl(this.image_data.inside_image_url) ,
                    check_out_image_url : getImageUrl(this.image_data.check_out_image_url),
                    company_front_image_url : getImageUrl(this.image_data.company_front_image_url),
                    
                },
                cover_url : getImageUrl(this.image_data.cover_url),
                company_type:this.current
            }
            let data={
                type:'store',
                key:'enterpriseInfo',
                content:JSON.stringify(this.settleInfo)
            }
            if(this.info.id<=0){
                this.$http.post(CACHE_COMMIT,data).then(res=>{
                })
            }

            this.$emit('enterprise',business_license,params,image,legal)
        },
        onDraft(){
            this.settleInfo={
                cate_name: this.cate_name,
                cate_id: this.cate_id,
                region_name: this.region_name,
                latitude: this.latitude,
                longitude: this.longitude,
                region_code: this.region_code,
                address: this.address,
                image_data: this.image_data,
                business_license: {
                    ...this.business_license,
                    license_url:getImageUrl(this.license_url),
                },
                legal_person:{
                    ...this.legal_person,
                    front_url: getImageUrl(this.front_url),
                    back_url: getImageUrl(this.back_url),
                    
                },
                image_data:{
                    head_image_url :getImageUrl(this.image_data.head_image_url),
                    inside_image_url : getImageUrl(this.image_data.inside_image_url) ,
                    check_out_image_url : getImageUrl(this.image_data.check_out_image_url),
                    company_front_image_url : getImageUrl(this.image_data.company_front_image_url),
                    
                },
                cover_url : getImageUrl(this.image_data.cover_url),
                company_type:this.current
            }
            let data={
                type:'store',
                key:'enterpriseInfo',
                content:JSON.stringify(this.settleInfo)
            }
            console.log(this.settleInfo);
            
            this.$http.post(CACHE_COMMIT,data).then(res=>{
                this.$toast('暂存成功')
            })
        },
        backBtn(){
            this.$emit("goBack",0)
        }
    },
})
</script>
<style scoped lang="scss">
.shop_info {
    ::v-deep .van-icon {
        color: #c0c0c0 !important;
    }
}

.enterise_info_title {
    font-size: 0.28rem;
    font-weight: bold;
    background: #fff;
    padding: 0.32rem;

    span {
        color: red;
    }
}

.enterise_info_current {
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: .28rem;
    color: #333333;
    padding: 0rem .32rem 0.2rem 0.32rem;
    // line-height: 20px;
    text-align: left;
    font-style: normal;

    span {
        font-size: .24rem;
        color: #999999;
    }
}

.enterise_info_text {
    padding: 0.32rem;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 0.24rem;
    color: #F9301B;
    // line-height: 17px;
    text-align: left;
    font-style: normal;
}

.enterise_info_tab {
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    padding: 0.2rem;

    &_btn {
        width: 30%;
        border-radius: 0.15rem;
        // border: 1px solid red;
    }

    // ::v-deep .van-button__text{
    //     color: #F32A23;
    // }
}

.enterise_info_upload_title {
    font-size: 0.28rem;
    font-weight: bold;
    background: #fff;
    // padding: 0.2rem;
    text-align: center;
}

.shop_upload_text {
    // line-height: 0.5rem;
    line-height: .6rem;
    text-align: left;
    font-style: normal;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;

    div:nth-child(1) {
        // font-weight: 400;
        font-size: .28rem;
        color: #333333;

    }

    div:nth-child(2) {
        font-size: .24rem;
        color: #999999;
    }

    div:nth-child(3) {
        font-size: 0.24rem;
        color: #F9301B;
    }
}

.shop_upload_img {
    width: .64rem;
    height: .64rem;
    margin-top: 70%;
}

.tianjia_pic {
    width: 100%;
}

.tianjia_text {
    width: 100%;
    position: absolute;
    bottom: -20px;
    left: 30%;
    transform: translateX(-50%);
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: .24rem;
    color: #999999;
    // line-height: 17px;
    font-style: normal;
}
.popup_example{
    padding-bottom: 0.2rem;
    img{
        width: 100%;
    }
    div{
        padding: 0 .12rem;
        box-sizing: border-box;
        font-size: 0.28rem;
    }

}
</style>
